#include "wifimanage.h"
#include "ui_wifimanage.h"
#include <QDebug>
#include <QListView>
#include <QStyledItemDelegate>
#include <QPushButton>
#include <QCompleter>
#include <QLineEdit>
#include <QStringListModel>
#include <QGraphicsDropShadowEffect>
#include <QScrollBar>
#include <QJsonDocument>
#include <QJsonParseError>
#include <QJsonObject>
#include <QJsonArray>
#include <QJsonValue>
#include "wifiitem.h"
#include "newwifi.h"
#include "amendwifi.h"
#include "messagepops.h"
#include "lcombobox.h"
#include "operationdocument.h"
#include "function/function.h"

extern QByteArray token;//http返回id码

//WiFi管理界面
WiFiManage::WiFiManage(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::WiFiManage)
{
    ui->setupUi(this);

    this->setParent(parent);
    this->setWindowFlags(Qt::CustomizeWindowHint|Qt::FramelessWindowHint);
    this->hide();

    //遮罩窗口突出显示弹窗
    mpShadeWindow = new QWidget(parent);
    QString str("QWidget{background-color:rgba(51,51,51,0.4);}");
    mpShadeWindow->setStyleSheet(str);
    mpShadeWindow->setGeometry(0, 0, 1, 1);
    mpShadeWindow->hide();

    mps=new MessagePops(this);//初始化提示窗口对象
    mps->setWindowFlags(Qt::FramelessWindowHint|Qt::Window);   //设置无边框 非顶级窗口
    mps->hide();
    connect(mps,SIGNAL(sendMessage(QString)),this,SLOT(receMessage(QString)));


    initialize();
}

WiFiManage::~WiFiManage()
{
    delete ui;
}

//解析显示WIFI数据
void WiFiManage::analysisWiFiWorkers(QByteArray Data, int location_)
{
    QFont font;
    font.setFamily(QStringLiteral("Microsoft YaHei"));//设置字体
    font.setPixelSize(16);//字体大小
    font.setWeight(QFont::Normal);//设置文字粗细
    font.setLetterSpacing(QFont::PercentageSpacing,120);//120字间距，默认100

    sign1 = 0;
//    signature_pathNumber2 = 0;
    ui->tableWidget->setRowCount(0);
    ui->tableWidget->setRowCount(RowCount);

    //获取QComboBox列表项的当前项的文字
    QString type = comboBoxText(lComboBox);//WiFi类型
    QString name = ui->lineEdit->text();//WiFi名称

    ui->tableWidget->clear();//清除内容，重新匹配

    medicalWiFiData = Data;

    //把获取的json数据标准化存储
    QJsonParseError myerr;
    QJsonDocument mydoc=QJsonDocument::fromJson(medicalWiFiData,&myerr);

    //获取最外面的对象
    QJsonObject obj=mydoc.object();

     //继续获取键值对中的键和值(数组)
    QJsonArray val=obj.value("data").toArray();

    int number = 0;//记录人数

    for(int i=0; i<val.size(); i++)
    {
        QJsonObject  obj1=val.at(i).toObject();

        //obj1存放的就是数组中一个WIFI信息
        QString real_name = obj1.value("name").toString();
        if(!real_name.contains(name))   continue;

        int is_type=obj1.value("type").toInt();
        if(type != "全部")
        {
            if(is_type==1)
            {
                if(type == "药柜")
                    continue;
            }
            else if(is_type==2)
            {
                if(type == "公共")
                    continue;
            }
        }

        number++;

    }

    pagination = number/15;
    if(number%15 > 0)
    {
        pagination++;
    }
    qDebug()<<__LINE__<<"pagination="<<pagination;

    setNumber(524,810,36,36,pagination);
    location = location_;
    showButton();

    accountNumbers.clear();
    for(int i=0; i<val.size(); i++)
    {
        QJsonObject  obj1=val.at(i).toObject();

        //obj1存放的就是数组中一个WIFI信息
        QString real_name = obj1.value("name").toString();

        accountNumbers.append(real_name);
    }
}

//解析显示WIFI数据----翻页
void WiFiManage::analysisWiFiWorkers2(QByteArray Data, int page)
{
    int number2 = (page-1)*15;

    QFont font;
    font.setFamily(QStringLiteral("Microsoft YaHei"));//设置字体
    font.setPixelSize(16);//字体大小
    font.setWeight(QFont::Normal);//设置文字粗细
    font.setLetterSpacing(QFont::PercentageSpacing,120);//120字间距，默认100

    sign1 = 0;
    ui->tableWidget->setRowCount(0);
    ui->tableWidget->setRowCount(RowCount);

    //获取QComboBox列表项的当前项的文字
    QString type = comboBoxText(lComboBox);//WiFi类型
    QString name = ui->lineEdit->text();//WiFi名称

    ui->tableWidget->clear();//清除内容，重新匹配

//    medicalWiFiData = Data;

    //把获取的json数据标准化存储
    QJsonParseError myerr;
    QJsonDocument mydoc=QJsonDocument::fromJson(Data,&myerr);

    //获取最外面的对象
    QJsonObject obj=mydoc.object();

     //继续获取键值对中的键和值(数组)
    QJsonArray val=obj.value("data").toArray();

    int number = 0;//记录人数

    for(int i=0; i<val.size(); i++)
    {
        QJsonObject  obj1=val.at(i).toObject();

        //obj1存放的就是数组中一个WIFI信息
        QString real_name = obj1.value("name").toString();//表格WiFi名称
//        int cabinet_number = obj1.value("cabinet_number").toInt();//药柜编号
        int connect_count = obj1.value("connect_count").toInt();//连接设备数量

        QString password = obj1.value("password").toString();
        if(!real_name.contains(name))   continue;

        int is_type=obj1.value("type").toInt();
        if(type != "全部")
        {
            if(is_type==1)
            {
                if(type == "药柜")
                    continue;
            }
            else if(is_type==2)
            {
                if(type == "公共")
                    continue;
            }
        }

        number++;
        if(number <= number2)
        {
            continue;
        }

        //添加WIFI名称
        QTableWidgetItem *qtwi=new QTableWidgetItem();

        qtwi->setText(real_name);//设置单元格中的文本
        qtwi->setFont(font);
        qtwi->setForeground(QBrush(QColor(102, 102, 102)));//设置单元格中字体的颜色
        qtwi->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);//设置单元格中文本的对齐方式
        ui->tableWidget->setItem(sign1,0,qtwi);

//        //密码
//        QTableWidgetItem *qtwi2=new QTableWidgetItem();

//        if(password.size()>8)
//        {
//            QString str = QString("%1....%2").arg(password.mid(0,3)).arg(password.mid(password.size()-3,3));
//            qtwi2->setText(str);//设置单元格中的文本
//        }
//        else
//        {
//            qtwi2->setText(password);//设置单元格中的文本
//        }

//        qtwi2->setFont(font);
//        qtwi2->setForeground(QBrush(QColor(102, 102, 102)));//设置单元格中字体的颜色
//        qtwi2->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);//设置单元格中文本的对齐方式
//        ui->tableWidget->setItem(sign1,1,qtwi2);

        //类型
        QTableWidgetItem *qtwi3=new QTableWidgetItem();

        if(is_type == 1)
        {
            qtwi3->setText("公共");//设置单元格中的文本
        }
        else if(is_type == 2)
        {
            qtwi3->setText("柜子");//设置单元格中的文本
        }

        qtwi3->setFont(font);
        qtwi3->setForeground(QBrush(QColor(102, 102, 102)));//设置单元格中字体的颜色
        qtwi3->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);//设置单元格中文本的对齐方式
        ui->tableWidget->setItem(sign1,1,qtwi3);

        //连接设备数量
        QTableWidgetItem *qtwi4=new QTableWidgetItem();

        qtwi4->setText(QString::number(connect_count));//设置单元格中的文本
        qtwi4->setFont(font);
        qtwi4->setForeground(QBrush(QColor(102, 102, 102)));//设置单元格中字体的颜色
        qtwi4->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);//设置单元格中文本的对齐方式
        ui->tableWidget->setItem(sign1,2,qtwi4);

        // 创建QPushButton控件
        WiFiItem *pWiFiItem = new WiFiItem(this);
        connect(pWiFiItem,SIGNAL(sendWiFiItem(QString)),this,SLOT(receWiFiItem(QString)));
        ui->tableWidget->setCellWidget(sign1,3,pWiFiItem);

        sign1++;
    }
}

//自定义操作接收槽函数
void WiFiManage::receWiFiItem(QString data)
{
    QWidget *w_parent = (QWidget*)sender();
    int x = w_parent->frameGeometry().x();
    int y = w_parent->frameGeometry().y();
    QModelIndex index = ui->tableWidget->indexAt(QPoint(x,y));
    int row = index.row();
    int col = index.column();


    if(data == "1")
    {
        OnBtnClicked(row,col);
    }
    else if(data == "2")
    {
        OnBtnClicked2(row,col);
    }
}

//自定义新建用户接收槽函数
void WiFiManage::receNewWifi(QString data)
{
    closeShadeWindow();//关闭遮罩窗口

    if(data == "1")
    {
        emit sendWiFiManage(1, location);//发送刷新所有wifi信息
    }
    else if(data == "2")
    {
        //新建wifi界面点击了关闭按钮
    }
}

//自定义修改WiFi接收槽函数
void WiFiManage::receAmendWifi(QString data)
{
    closeShadeWindow();//关闭遮罩窗口

    if(data == "1")
    {
        emit sendWiFiManage(1, location);//发送刷新所有wifi信息
    }
    else if(data == "2")
    {
        //修改wifi界面点击了关闭按钮
    }
}

void WiFiManage::receMessage(QString data)
{
    if(data == "2")
    {
        //取消删除WiFi
    }
    else if(data == "3")
    {
        //确定删除WiFi
        QNetworkRequest request;
        QNetworkAccessManager* naManager = new QNetworkAccessManager(this);
        connect(naManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(requestFinished(QNetworkReply*)));

        request.setHeader(QNetworkRequest::ContentTypeHeader,QVariant("application/json"));
        request.setUrl(QUrl::fromUserInput(URLName_2("delete-wifi/")));
        request.setRawHeader("token",token);

        QJsonObject object;
        object.insert("id",removeID);//id

        QByteArray byte_array = QJsonDocument(object).toJson();
        qDebug()<<__LINE__<< "user  info " << object;

        naManager->post(request,byte_array);//发起post请求
        mps->setText("正在删除");
        mps->show();
    }
}

//自定义下拉复选框接收槽函数
void WiFiManage::receLComboBox(int n, QString)
{
    if(n == 1)
    {
        analysisWiFiWorkers(medicalWiFiData);
    }
}

//点击了类型下拉框
void WiFiManage::on_comboBox_activated(const QString &)
{
    analysisWiFiWorkers(medicalWiFiData);
}

//翻页触发槽函数
void WiFiManage::FlipOver()
{
    //获取信号的发送者
    QPushButton *ret=(QPushButton *)sender();

//    setPbStyleSheet();

//    ret->setStyleSheet("background: #1B89CC;border-radius: 10px;font-size: 18px;font-family: Microsoft YaHei;color: #FBFBFB;");
    location = ret->text().toInt();

    showButton();
}

//左翻页槽函数
void WiFiManage::LeftOver()
{
    location--;

    if(location <= 1)
    {
        ui->pbl->setStyleSheet("border: 1px solid #999999;border-radius: 10px;");
        setCursor(Qt::ArrowCursor); //设置默认鼠标样式
    }
    else
    {
        ui->pbl->setStyleSheet("border: 1px solid #666666;border-radius: 10px;");
    }
    if(location >= pagination)
    {
        ui->pbr->setStyleSheet("border: 1px solid #999999;border-radius: 10px;");
        setCursor(Qt::ArrowCursor); //设置默认鼠标样式
    }
    else
    {
        ui->pbr->setStyleSheet("border: 1px solid #666666;border-radius: 10px;");
    }
    showButton();
}

//右翻页槽函数
void WiFiManage::RightOver()
{
    location++;

    if(location <= 1)
    {
        ui->pbl->setStyleSheet("border: 1px solid #999999;border-radius: 10px;");
        setCursor(Qt::ArrowCursor); //设置默认鼠标样式
    }
    else
    {
        ui->pbl->setStyleSheet("border: 1px solid #666666;border-radius: 10px;");
    }
    if(location >= pagination)
    {
        ui->pbr->setStyleSheet("border: 1px solid #999999;border-radius: 10px;");
        setCursor(Qt::ArrowCursor); //设置默认鼠标样式
    }
    else
    {
        ui->pbr->setStyleSheet("border: 1px solid #666666;border-radius: 10px;");
    }
    showButton();
}

//删除WiFi接收槽函数
void WiFiManage::requestFinished(QNetworkReply *reply)
{
    QByteArray bytes = reply->readAll();

    qDebug() <<__LINE__<< QString(bytes) ;

    if(bytes.contains("ok"))
    {
        mps->setText("删除成功");
        mps->show();
        emit sendWiFiManage(1, 1);//发送刷新所有用户信息
    }
    else
    {
        mps->setText("删除失败");
        mps->show();
    }

}

//初始化界面
void WiFiManage::initialize()
{
    //部件事件过滤的注册
    ui->pushButton->installEventFilter(this);
    ui->pushButton_2->installEventFilter(this);
    ui->pushButton_3->installEventFilter(this);
    ui->comboBox->installEventFilter(this);
    ui->pbl->installEventFilter(this);
    ui->pbr->installEventFilter(this);
    ui->pb1->installEventFilter(this);
    ui->pb2->installEventFilter(this);
    ui->pb3->installEventFilter(this);
    ui->pb4->installEventFilter(this);
    ui->pb5->installEventFilter(this);

    lComboBox = new LComboBox(this);
    connect(lComboBox,SIGNAL(sendLComboBox(int,QString)),this,SLOT(receLComboBox(int,QString)));
    lComboBox->setGeometry(135,26,150,30);
    QStringList list2;
    list2<<"公共"<<"药柜";
    lComboBox->setTexe(list2);

    //设置QComboBox样式
    setcomboBox(ui->comboBox);

    //设置新建按钮图片
    ui->pushButton->setIcon(QPixmap(":/new/prefix1/resource/11.png"));

    QFont font;
    font.setFamily(QStringLiteral("Microsoft YaHei"));//设置字体
    font.setPixelSize(16);//字体大小
    font.setLetterSpacing(QFont::PercentageSpacing,120);//120字间距，默认100

    ui->label->setFont(font);
    ui->label_2->setFont(font);
    ui->lineEdit->setFont(font);

    {
        QIcon icon;
        icon.addFile(tr(":/new/prefix1/resource/12.png"));
        ui->pbl->setIcon(icon);
        ui->pbl->setStyleSheet("border: 1px solid #999999;border-radius: 10px;");

        QPixmap icon1(tr(":/new/prefix1/resource/13.png"));
        ui->pbr->setIcon(icon1);
    //    ui->pbr->setFixedSize(icon1.size());

        connect(ui->pb1,SIGNAL(clicked()),this,SLOT(FlipOver()));
        connect(ui->pb2,SIGNAL(clicked()),this,SLOT(FlipOver()));
        connect(ui->pb3,SIGNAL(clicked()),this,SLOT(FlipOver()));
        connect(ui->pb4,SIGNAL(clicked()),this,SLOT(FlipOver()));
        connect(ui->pb5,SIGNAL(clicked()),this,SLOT(FlipOver()));

        PB[0] = ui->pb1;
        PB[1] = ui->pb2;
        PB[2] = ui->pb3;
        PB[3] = ui->pb4;
        PB[4] = ui->pb5;

        connect(ui->pbl,SIGNAL(clicked()),this,SLOT(LeftOver()));
        connect(ui->pbr,SIGNAL(clicked()),this,SLOT(RightOver()));

        showButton();
    }

    {
        ui->tableWidget->setColumnCount(4); //设置列数为11
    //    ui->tableWidget->setHorizontalHeaderLabels(QStringList()<<"药品名"<<"规格"<<"数量");

        //设置表格的行数
        ui->tableWidget->verticalHeader()->setVisible(false); //隐藏列表头
        ui->tableWidget->horizontalHeader()->setVisible(false); //隐藏行表头
        ui->tableWidget->setRowCount(RowCount);

        ui->tableWidget->setColumnWidth(0,280);
        ui->tableWidget->setColumnWidth(1,277);
        ui->tableWidget->setColumnWidth(2,179);
        ui->tableWidget->setColumnWidth(3,170);

        ui->tableWidget->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);//隐藏上下滚动条
        ui->tableWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);//隐藏左右滚动条
        ui->tableWidget->setFocusPolicy(Qt::NoFocus);//解决选中虚框问题(选中后变灰一点)
        ui->tableWidget->setSelectionMode(QAbstractItemView::NoSelection);// 不能选择单元格
        ui->tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);//禁止编辑
        ui->tableWidget->verticalHeader()->setDefaultSectionSize(40);//可以设置tableview所有列的默认行高为40
    }

    QStringList headerText;
    headerText<<"WIFI"<<"类型"<<"连接设备数量"<<"操作";
    QTableWidget *Headline = new QTableWidget(this);
    userDefinedHeadline(ui->tableWidget, Headline, headerText);
}

//设置QComboBox样式
void WiFiManage::setcomboBox(QComboBox *comboBox)
{
    comboBox->setView(new  QListView());

    //设置标题字间距,外阴影
    QFont font;
    font.setLetterSpacing(QFont::PercentageSpacing,120);//120字间距，默认100
    QAbstractItemView* view = comboBox->view();
    view->setFont(font);//设置标题字间距
    QGraphicsDropShadowEffect* effect = new QGraphicsDropShadowEffect;
    effect->setBlurRadius(10);//阴影半径
//    effect->setColor(Qt::black);
    effect->setColor(QColor(38, 78, 119, 127));//阴影颜色
    effect->setOffset(0, 0);
    view->setGraphicsEffect(effect);
    view->update();

    static_cast<QWidget*>(view->parent())->setStyleSheet("QMainWindow{border:none;background-color: rgb(255, 255, 255);}");

    QWidget* container = static_cast<QWidget*>(view->parent());
//    container->setAttribute(Qt::WA_TranslucentBackground);
    container->setWindowFlag(Qt::FramelessWindowHint);
    container->setWindowFlag(Qt::NoDropShadowWindowHint);
}

void WiFiManage::userDefinedHeadline(QTableWidget *tableWidget, QTableWidget *Headline, QStringList headerText)
{
    QFont font;
    font.setFamily("Microsoft YaHei");//设置字体
    //设置为粗体
    font.setBold(true);
    //字体大小
    font.setPixelSize(16);
    font.setLetterSpacing(QFont::PercentageSpacing,130);//120字间距，默认100

//    int iRow = tableWidget->rowCount();//行数
    int iColumn = tableWidget->columnCount();//列数
    int iWidth = tableWidget->width();//宽度
    int iX = tableWidget->x();//x轴坐标
    int iY = tableWidget->y();//x轴坐标

    //设置表格的行数
    Headline->verticalHeader()->setVisible(false); //隐藏列表头
    Headline->horizontalHeader()->setVisible(false); //隐藏行表头
    Headline->setRowCount(1);

    Headline->verticalHeader()->setDefaultSectionSize(40);//可以设置tableview所有列的默认行高为32
    Headline->setEditTriggers(QAbstractItemView::NoEditTriggers);//禁止编辑
    Headline->verticalScrollBar()->setDisabled(true); // 禁用滚动
    Headline->horizontalScrollBar()->setDisabled(true); // 禁用滚动
    Headline->setAutoScroll(false);//去掉自动滚动
    tableWidget->verticalScrollBar()->setDisabled(true); // 禁用滚动
    tableWidget->horizontalScrollBar()->setDisabled(true); // 禁用滚动
    tableWidget->setAutoScroll(false);//去掉自动滚动


    Headline->setColumnCount(iColumn); //设置列数
//    Headline->setHorizontalHeaderLabels(headerText);//设置标题
    Headline->setGeometry(iX,iY-40,iWidth,40);//设置位置和大小

//    Headline->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);/* 自适应所有列，让它布满空间 */
    //设置每列长度
    Headline->setColumnWidth(0,280);
    Headline->setColumnWidth(1,277);
    Headline->setColumnWidth(2,179);
    Headline->setColumnWidth(3,170);

    Headline->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);//隐藏上下滚动条
    Headline->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);//隐藏左右滚动条
    Headline->setFocusPolicy(Qt::NoFocus);//解决选中虚框问题(选中后变灰一点)
    Headline->setSelectionMode(QAbstractItemView::NoSelection);// 不能选择单元格

    //添加正文内容  设置标题
    for(int i=0; i<headerText.size(); i++)
    {
        QTableWidgetItem *qtwi=new QTableWidgetItem();
        qtwi->setText(headerText.at(i));//设置单元格中的文本
//        qtwi->setFlags(qtwi->flags() & ~Qt::ItemIsSelectable);//表格不可被选中
        qtwi->setBackground(QBrush("#F1F6F9"));//设置单元格的背景
        qtwi->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);//设置单元格中文本的对齐方式
        qtwi->setFont(font);//设置单元格中文本的字体
        Headline->setItem(0,i,qtwi);
    }

    tableWidget->setStyleSheet("QTableWidget {padding: 1px;border: none;\
    border-left: 1px solid #999999;\
    border-right: 1px solid #999999;\
    border-top: 1px solid #cccccc;\
    border-bottom: 1px solid #999999;}");

    //设置表格边逛
    Headline->setStyleSheet("QTableWidget {padding: 1px;border: none;\
    border-left: 1px solid #999999;\
    border-right: 1px solid #999999;\
    border-top: 1px solid #999999;\
    border-bottom: 0px solid gray;}");
}

//修改WiFi信息
void WiFiManage::OnBtnClicked(int row, int column)
{
    qDebug()<<__LINE__<<"选择第几行="<<row<<"选择第几列="<<column;

    //接下来自定义要处理的
    int id=-1;
    QJsonObject userinfo;
    QString username = ui->tableWidget->item(row,0)->text();

    //把获取的json数据标准化存储
    QJsonParseError myerr;
    QJsonDocument mydoc=QJsonDocument::fromJson(medicalWiFiData,&myerr);

    //获取最外面的对象
    QJsonObject obj=mydoc.object();
    //继续获取键值对中的键和值(数组)
   QJsonArray array=obj.value("data").toArray();

    for(int i=0;i<array.size();i++)
    {
        //obj1存放的就是数组中一个医护人员信息
        userinfo=array.at(i).toObject();

        //文件路径
        QString val4=userinfo.value("name").toString();
        if(username == val4)
        {
            id = 1;

            break;
        }

    }
    if(id == -1)
    {
        qDebug()<<__LINE__<<"没有该用户";
        emit sendWiFiManage(1, location);//发送刷新所有用户信息
        return;
    }

    showShadeWindow();//显示遮罩窗口

    amendwifi = new amendWiFi(this);
    connect(amendwifi,SIGNAL(sendAmendWifi(QString)),this,SLOT(receAmendWifi(QString)));
    amendwifi->setInio(accountNumbers,userinfo);
    amendwifi->exec();

}

//删除WiFi信息
void WiFiManage::OnBtnClicked2(int row, int column)
{
    qDebug()<<__LINE__<<"选择第几行="<<row<<"选择第几列="<<column;

    //接下来自定义要处理的
    int id=-1;
    QJsonObject userinfo;
    QString username = ui->tableWidget->item(row,0)->text();

    //把获取的json数据标准化存储
    QJsonParseError myerr;
    QJsonDocument mydoc=QJsonDocument::fromJson(medicalWiFiData,&myerr);

    //获取最外面的对象
    QJsonObject obj=mydoc.object();
    //继续获取键值对中的键和值(数组)
   QJsonArray array=obj.value("data").toArray();

    for(int i=0;i<array.size();i++)
    {
        //obj1存放的就是数组中一个医护人员信息
        userinfo=array.at(i).toObject();

        //文件路径
        QString val4=userinfo.value("name").toString();
        if(username == val4)
        {
            id = 1;

            break;
        }

    }
    if(id == -1)
    {
        qDebug()<<__LINE__<<"没有该用户";
        emit sendWiFiManage(1, location);//发送刷新所有用户信息
        return;
    }

    removeID = userinfo.value("id").toInt();
    mps->setTexts("确定删除该WiFi!");
    mps->show();
}

bool WiFiManage::eventFilter(QObject *watched, QEvent *event)
{
    if(ui->pushButton==watched)
    {
        if(QEvent::Enter==event->type())
        {
            ui->pushButton->setStyleSheet("background: #F1F6F9;border: 1px solid #3699FF;border-radius: 15px;font-size: 16px;font-family: Microsoft YaHei;color: #1B89CC;");
            ui->pushButton->setIcon(QPixmap(":/new/prefix1/resource/20.png"));
            setCursor(Qt::PointingHandCursor); //设置鼠标样式
        }
        else if(QEvent::Leave==event->type())
        {
            ui->pushButton->setStyleSheet("background: #F1F6F9;border-radius: 15px;font-size: 16px;font-family: Microsoft YaHei;color: #333333;");
            ui->pushButton->setIcon(QPixmap(":/new/prefix1/resource/11.png"));
            setCursor(Qt::ArrowCursor); //设置默认鼠标样式
        }
    }
    if(ui->pushButton_2==watched)
    {
        if(QEvent::Enter==event->type())
        {
            ui->pushButton_2->setStyleSheet("background: #F1F6F9;border: 1px solid #3699FF;border-radius: 15px;font-size: 16px;font-family: Microsoft YaHei;color: #1B89CC;padding-left:2px;padding-bottom:3px;");

//            QCursor cursor(QPixmap(":/new/prefix1/resource/18.png"), -1, -1); //-1 -1表示鼠标热点在中心点
//            setCursor(cursor); //设置自定义的鼠标样式
            setCursor(Qt::PointingHandCursor); //设置鼠标样式
        }
        else if(QEvent::Leave==event->type())
        {
            ui->pushButton_2->setStyleSheet("background: #F1F6F9;border-radius: 15px;font-size: 16px;font-family: Microsoft YaHei;color: #333333;padding-left:2px;padding-bottom:3px;");
            setCursor(Qt::ArrowCursor); //设置默认鼠标样式
        }
    }
    if(ui->pushButton_3==watched)
    {
        if(QEvent::Enter==event->type())
        {
            ui->pushButton_3->setStyleSheet("background: #F1F6F9;border: 1px solid #3699FF;border-radius: 15px;font-size: 16px;font-family: Microsoft YaHei;color: #1B89CC;padding-left:2px;padding-bottom:3px;");
            setCursor(Qt::PointingHandCursor); //设置鼠标样式
        }
        else if(QEvent::Leave==event->type())
        {
            ui->pushButton_3->setStyleSheet("background: #F1F6F9;border-radius: 15px;font-size: 16px;font-family: Microsoft YaHei;color: #333333;padding-left:2px;padding-bottom:3px;");
            setCursor(Qt::ArrowCursor); //设置鼠标样式
        }
    }

    if(ui->comboBox==watched)
    {
        if(QEvent::Enter==event->type())
        {
            setCursor(Qt::PointingHandCursor); //设置鼠标样式
        }
        else if(QEvent::Leave==event->type())
        {
            setCursor(Qt::ArrowCursor); //设置鼠标样式
        }
    }

    if(ui->pbl==watched)
    {
        if(QEvent::Enter==event->type())
        {
            if(ifpbl == 1)
            {
                setCursor(Qt::PointingHandCursor); //设置鼠标样式
            }

        }
        else if(QEvent::Leave==event->type())
        {
            setCursor(Qt::ArrowCursor); //设置鼠标样式
        }
    }
    if(ui->pbr==watched)
    {
        if(QEvent::Enter==event->type())
        {
            if(ifpbr == 1)
            {
                setCursor(Qt::PointingHandCursor); //设置鼠标样式
            }
        }
        else if(QEvent::Leave==event->type())
        {
            setCursor(Qt::ArrowCursor); //设置鼠标样式
        }
    }
    if(ui->pb1==watched)
    {
        if(QEvent::Enter==event->type())
        {
            setCursor(Qt::PointingHandCursor); //设置鼠标样式
        }
        else if(QEvent::Leave==event->type())
        {
            setCursor(Qt::ArrowCursor); //设置鼠标样式
        }
    }
    if(ui->pb2==watched)
    {
        if(QEvent::Enter==event->type())
        {
            setCursor(Qt::PointingHandCursor); //设置鼠标样式
        }
        else if(QEvent::Leave==event->type())
        {
            setCursor(Qt::ArrowCursor); //设置鼠标样式
        }
    }
    if(ui->pb3==watched)
    {
        if(QEvent::Enter==event->type())
        {
            setCursor(Qt::PointingHandCursor); //设置鼠标样式
        }
        else if(QEvent::Leave==event->type())
        {
            setCursor(Qt::ArrowCursor); //设置鼠标样式
        }
    }
    if(ui->pb4==watched)
    {
        if(QEvent::Enter==event->type())
        {
            setCursor(Qt::PointingHandCursor); //设置鼠标样式
        }
        else if(QEvent::Leave==event->type())
        {
            setCursor(Qt::ArrowCursor); //设置鼠标样式
        }
    }
    if(ui->pb5==watched)
    {
        if(QEvent::Enter==event->type())
        {
            setCursor(Qt::PointingHandCursor); //设置鼠标样式
        }
        else if(QEvent::Leave==event->type())
        {
            setCursor(Qt::ArrowCursor); //设置鼠标样式
        }
    }
    return QObject::eventFilter(watched,event);
}

//设置翻页初始样式
void WiFiManage::setPbStyleSheet()
{
    ui->pb1->setStyleSheet("border: 1px solid #666666;border-radius: 10px;font-size: 18px;font-family: Microsoft YaHei;color: #666666;");
    ui->pb2->setStyleSheet("border: 1px solid #666666;border-radius: 10px;font-size: 18px;font-family: Microsoft YaHei;color: #666666;");
    ui->pb3->setStyleSheet("border: 1px solid #666666;border-radius: 10px;font-size: 18px;font-family: Microsoft YaHei;color: #666666;");
    ui->pb4->setStyleSheet("border: 1px solid #666666;border-radius: 10px;font-size: 18px;font-family: Microsoft YaHei;color: #666666;");
    ui->pb5->setStyleSheet("border: 1px solid #666666;border-radius: 10px;font-size: 18px;font-family: Microsoft YaHei;color: #666666;");
}

//设置表格页数小于5页
void WiFiManage::setNumber(int x, int y, int w, int h, int number)
{
    if(number<=5)
    {
        x = x-51-number*33;
    }
    else
    {
        x = x-51-5*33;
        number=5;
    }

    if(number <= 1)
    {
        ui->pb1->show();
        ui->pb2->hide();
        ui->pb3->hide();
        ui->pb4->hide();
        ui->pb5->hide();

        ui->pbl->setGeometry(x,y,w,h);
        ui->pb1->setGeometry(x+66,y,w,h);
        ui->pbr->setGeometry(x+66*2,y,w,h);
    }
    else if(number == 2)
    {
        ui->pb1->show();
        ui->pb2->show();
        ui->pb3->hide();
        ui->pb4->hide();
        ui->pb5->hide();

        ui->pbl->setGeometry(x,y,w,h);
        ui->pb1->setGeometry(x+66,y,w,h);
        ui->pb2->setGeometry(x+66*2,y,w,h);
        ui->pbr->setGeometry(x+66*3,y,w,h);
    }
    else if(number == 3)
    {
        ui->pb1->show();
        ui->pb2->show();
        ui->pb3->show();
        ui->pb4->hide();
        ui->pb5->hide();

        ui->pbl->setGeometry(x,y,w,h);
        ui->pb1->setGeometry(x+66,y,w,h);
        ui->pb2->setGeometry(x+66*2,y,w,h);
        ui->pb3->setGeometry(x+66*3,y,w,h);
        ui->pbr->setGeometry(x+66*4,y,w,h);
    }
    else if(number == 4)
    {
        ui->pb1->show();
        ui->pb2->show();
        ui->pb3->show();
        ui->pb4->show();
        ui->pb5->hide();

        ui->pbl->setGeometry(x,y,w,h);
        ui->pb1->setGeometry(x+66,y,w,h);
        ui->pb2->setGeometry(x+66*2,y,w,h);
        ui->pb3->setGeometry(x+66*3,y,w,h);
        ui->pb4->setGeometry(x+66*4,y,w,h);
        ui->pbr->setGeometry(x+66*5,y,w,h);
    }
    else if(number >= 5)
    {
        ui->pb1->show();
        ui->pb2->show();
        ui->pb3->show();
        ui->pb4->show();
        ui->pb5->show();

        ui->pbl->setGeometry(x,y,w,h);
        ui->pb1->setGeometry(x+66,y,w,h);
        ui->pb2->setGeometry(x+66*2,y,w,h);
        ui->pb3->setGeometry(x+66*3,y,w,h);
        ui->pb4->setGeometry(x+66*4,y,w,h);
        ui->pb5->setGeometry(x+66*5,y,w,h);
        ui->pbr->setGeometry(x+66*6,y,w,h);
    }
}

//按钮显示位置样式
void WiFiManage::showButton()
{
    setPbStyleSheet();

    if(location <= 1)
    {
        //禁用左按钮
        ui->pbl->setEnabled(false);
//        setCursor(Qt::ArrowCursor); //设置默认鼠标样式
        ifpbl = 0;
    }
    else
    {
        ui->pbl->setEnabled(true);
        ifpbl = 1;
    }
    if(location >= pagination)
    {
        //禁用右按钮
        ui->pbr->setEnabled(false);
//        setCursor(Qt::ArrowCursor); //设置默认鼠标样式
        ifpbr = 0;
    }
    else
    {
        ui->pbr->setEnabled(true);
        ifpbr = 1;
    }


    if(pagination<=5)
    {
        PB[location-1]->setStyleSheet("background: #1B89CC;border-radius: 10px;font-size: 18px;font-family: Microsoft YaHei;color: #FBFBFB;");
    }
    else
    {
        if(location<=2)
        {
            for(int i=0;i<5;i++)
            {
                PB[i]->setText(QString::number(i+1));
            }
            PB[location-1]->setStyleSheet("background: #1B89CC;border-radius: 10px;font-size: 18px;font-family: Microsoft YaHei;color: #FBFBFB;");
        }
        else if((pagination-location)<=2)
        {
            for(int i=0;i<5;i++)
            {
                PB[i]->setText(QString::number(pagination-4+i));
            }
            PB[4-(pagination-location)]->setStyleSheet("background: #1B89CC;border-radius: 10px;font-size: 18px;font-family: Microsoft YaHei;color: #FBFBFB;");
        }
        else
        {
            for(int i=0;i<5;i++)
            {
                PB[i]->setText(QString::number(location-2+i));
            }
            PB[2]->setStyleSheet("background: #1B89CC;border-radius: 10px;font-size: 18px;font-family: Microsoft YaHei;color: #FBFBFB;");
        }
    }

    analysisWiFiWorkers2(medicalWiFiData, location);
}

//解析获取comboBox选中文本
QString WiFiManage::comboBoxText(QComboBox *comboBox)
{
    QString text = comboBox->currentText();
    text = text.replace(" ","");

    return text;
}

//解析获取lcomboBox选中文本
QString WiFiManage::comboBoxText(LComboBox *comboBox)
{
    return comboBox->text();
}

//显示遮罩窗口
void WiFiManage::showShadeWindow()
{
    QWidget *parentWidget=this->parentWidget();
    mpShadeWindow->setGeometry(0, 0, parentWidget->width(), parentWidget->height());
    mpShadeWindow->show();
}

//关闭遮罩窗口
void WiFiManage::closeShadeWindow()
{
    mpShadeWindow->hide();
    mpShadeWindow->setGeometry(0,0,1,1);
}

//WiFi输入框按下回车
void WiFiManage::on_lineEdit_returnPressed()
{
    analysisWiFiWorkers(medicalWiFiData);
}

//点击搜索按钮
void WiFiManage::on_pushButton_3_clicked()
{
    analysisWiFiWorkers(medicalWiFiData);
}

//点击重置按钮
void WiFiManage::on_pushButton_2_clicked()
{
    ui->lineEdit->clear();
//    ui->comboBox->setCurrentIndex(0);//设置当前项为第一项
    lComboBox->reset();

    emit sendWiFiManage(1, 1);//发送刷新所有用户信息
}

//点击新建wifi按钮
void WiFiManage::on_pushButton_clicked()
{
    showShadeWindow();//显示遮罩窗口

    newWiFi *newwf = new newWiFi(this);
    connect(newwf,SIGNAL(sendNewWifi(QString)),this,SLOT(receNewWifi(QString)));
    newwf->setInio(accountNumbers);
    newwf->exec();
}

void WiFiManage::on_lineEdit_textChanged(const QString &arg1)
{
    if(arg1.isEmpty())
    {
        OperationDocument::setqss(ui->lineEdit,":/new/prefix1/resource/myStyleSheet2.qss");

//        ui->lineEdit->setStyleSheet("/*默认样式*/QLineEdit{ \
//                                    border: 1px solid #666666;} \
//                                /*获取焦点时样式*/QLineEdit:focus {\
//                                    border: 1px solid #1B89CC; }");
    }
    else
    {
        OperationDocument::setqss(ui->lineEdit,":/new/prefix1/resource/myStyleSheet.qss");

//        ui->lineEdit->setStyleSheet("/*默认样式*/QLineEdit{ \
//                                    border: 1px solid #666666;\
//                                    border-radius: 8px;\
//                                    padding-left:8px;\
//                                    padding-bottom:2px;\
//                                    font-size: 15px;\
//                                    font-family: Microsoft YaHei;\
//                                    color: #999999;} \
//                                /*获取焦点时样式*/QLineEdit:focus {\
//                                    border: 1px solid #1B89CC;\
//                                    border-radius: 8px;\
//                                    padding-left:8px;\
//                                    padding-bottom:2px;\
//                                    font-size: 15px;\
//                                    font-family: Microsoft YaHei;\
//                                    color: #333333; } ");
    }
}
